package com.swu.education.service;

import com.swu.education.entity.CourseConnUser;
import com.swu.education.entity.User;
import com.swu.education.repository.CourseConnUserRepository;
import com.swu.education.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by nana on 2018/3/26.
 */
@Service
public class UserService {

  @Autowired
  CourseConnUserRepository courseConnUserRepository;

  @Autowired
  UserRepository userRepository;

  public List<User> getStuByCourseId(int courseId){
    List<User> userList = new ArrayList<>();
    try {
      List<CourseConnUser> courseConnUsersList = courseConnUserRepository.findAllByCourseId(courseId);
      for(int i=0;i<courseConnUsersList.size();i++){
        userList.add(userRepository.findById(courseConnUsersList.get(i).getUserId()));
      }
      return userList;
    }catch (Exception e){
      return userList;
    }
  }
}
